<?php

class Admin_Form_CatalogCategory_Add extends My_FormAdmin {

    protected $category;

    public function __construct($category, $options = null) {
        $this->category = $category;
        parent::__construct($options);
    }

    public function init() {
        $isRoot = $this->category ? false : true;
        $this->setMethod('post');
        $this->setAction($this->getView()->url(array('controller' => 'catalog-category', 'action' => 'add'), 'admin', true));

        if($isRoot) {
            $this->setTitle($this->translate('XXX_ADMIN_CATALOG_CATEGORY_ADD_ROOT_CATEGORY_FORM_TITLE'));
        } else {
            $this->setTitle($this->translate('XXX_ADMIN_CATALOG_CATEGORY_ADD_SUBCATEGORY_FORM_TITLE'));
        }

        $caption = new My_Form_Element_Content('tmp');
        if ($isRoot) {
            $caption->setValue('Dodawanie kategorii głównej');
        } else {
            $caption->setValue('Dodawanie podkategorii do ' . $this->category['name']);
        }
        $this->addElement($caption);

        $name = new Zend_Form_Element_Text('name');
        $name->setLabel(_('XXX_ADMIN_CATALOG_CATEGORY_FORM_NAME_LABEL'));
        $name->setRequired();
        $this->addElement($name);

        if ($isRoot) {
            $name = new Zend_Form_Element_Text('icon_path');
            $name->setLabel(_('XXX_ADMIN_CATALOG_CATEGORY_FORM_ICONPATH_LABEL'));
            $this->addElement($name);
        } else {
            $parent = new Zend_Form_Element_Hidden('id');
            $parent->setValue($this->category['code']);
            $this->addElement($parent);
        }
        

        $this->addSubmitElement();
    }

}

